import javax.swing.*;
import java.awt.event.*;

public class FastMVP extends JDialog {
    private final DialogCallBack mCallback;
    private JPanel contentPane;
    private JButton buttonOK;
    private JButton buttonCancel;

    private JTextField textField3;
    private JTextField textField2;
    private JCheckBox activityCheckBox;
    private JCheckBox fragmentCheckBox;
    private JCheckBox serviceCheckBox;
    private JCheckBox repositoryCheckBox;
    private JCheckBox apiCheckBox;
    private JTextField textField1;

    public FastMVP(DialogCallBack mCallback ) {
        this.mCallback =mCallback;
        setContentPane(contentPane);

        setModal(true);
        getRootPane().setDefaultButton(buttonOK);
        setSize(600, 300);
        setLocationRelativeTo(null);
        buttonOK.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onOK();
            }
        });

        buttonCancel.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onCancel();
            }
        });

        // call onCancel() when cross is clicked
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                onCancel();
            }
        });

        // call onCancel() on ESCAPE
        contentPane.registerKeyboardAction(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                onCancel();
            }
        }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    }

    private void onOK() {
        // add your code here
        if (null != mCallback){
            boolean activityCheckBoxisSelected = activityCheckBox.isSelected();
            boolean fragmentCheckBoxisSelected = fragmentCheckBox.isSelected();
            boolean serviceCheckBoxisSelected = serviceCheckBox.isSelected();
            boolean repositoryCheckBoxisSelected = repositoryCheckBox.isSelected();
            boolean apiCheckBoxisSelected = apiCheckBox.isSelected();

          if (!activityCheckBoxisSelected && !fragmentCheckBoxisSelected){
              return;
          }

            mCallback.ok(textField1.getText().trim(),   textField2.getText().trim(),textField3.getText().trim() ,activityCheckBoxisSelected ,fragmentCheckBoxisSelected,
                    serviceCheckBoxisSelected,
                    repositoryCheckBoxisSelected,apiCheckBoxisSelected
                    );
        }
        dispose();
    }

    private void onCancel() {
        // add your code here if necessary
        dispose();
    }

    public interface DialogCallBack{
        void ok(String packName, String ClassName ,String moduleName ,Boolean activity ,Boolean fragment ,Boolean service ,Boolean repository,Boolean api);
    }

}
